package com.thiscc.sum.logic;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bson.types.ObjectId;
import org.springframework.stereotype.Component;

import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import com.thiscc.sum.bean.Summary;
import com.thiscc.sum.constance.Global;
import com.thiscc.sum.constance.TableName;
import com.thiscc.sum.constance.Type;
import com.thiscc.sum.dao.CommonDao;
import com.thiscc.sum.dao.impl.CommonDaoImpl;
import com.thiscc.sum.utils.DBObjectUtils;
import com.thiscc.sum.utils.DateUtils;
import com.thiscc.sum.utils.JSONUtils;
import com.thiscc.sum.utils.ReduceCountUtils;
import com.thiscc.sum.utils.ReplayUtils;
import com.thiscc.sum.utils.RequestUtils;
import com.thiscc.sum.utils.StringUtils;
import com.thiscc.sum.utils.TableNameConstant;
import com.thiscc.sum.webservice.WebService;

/**
 * 总结的数据操作以及时间的控制
 * @author DK
 * @version 1.0
 */
@Component
public class SumLogic {

    private CommonDao commonDao = new CommonDaoImpl();
    public static Log log = LogFactory.getLog(SumLogic.class);

    /*-----------------------------------------------------------------------------------------*/
    /**
     * 
     * @param year
     * @param month
     * @param week
     * @param monthData
     * @createTime 2014-12-16
     * @since 1.0
     * @author Einstein
     */
    private List<Summary> getMonthDataByWeek(String s_uuid, int i_year, int i_month, int i_week, int i_currentFirstMonday, int i_days) {

        int i_start = (i_currentFirstMonday + (i_week - 1) * Global.DAYS_OF_WEEK);

        List<Summary> summaryArray = new ArrayList<Summary>();
        String s_startTime = i_year + "-" + i_month + "-" + i_start;

        Date date_start = DateUtils.stringToDate(s_startTime, DateUtils.DATE_FORMAT_DD);
        Date date_end = DateUtils.getDayOfAfterDays(DateUtils.stringToDate(s_startTime, DateUtils.DATE_FORMAT_DD), Global.DAYS_OF_WEEK - 1);

        // 循环7天,生成日，周，月，年总结
        for (int i = 0; i < Global.DAYS_OF_WEEK; i++) {

            int[] date = DateUtils.getYearMonthDay(DateUtils.getDayOfAfterDays(date_start, i));

            i_year = date[0];
            i_month = date[1];

            int day = date[2];
            Date date_time = DateUtils.getDayOfAfterDays(date_start, i);
            String time = DateUtils.dateToString(date_time, DateUtils.DATE_FORMAT_DD);

            if (i != Global.DAYS_OF_WEEK - 1) {
                // 日总结
                summaryArray.add(new Summary(Type.Day, Global.WEEK_CHINESS[i], Global.WEEK_ENGLISH[i], time, i_year, i_month, day));
            }
            if (i == Global.DAYS_OF_WEEK - 1) {
                // 周末，需要周总结
                summaryArray.add(new Summary(Type.Week, Global.WEEK_CHINESS[i], Global.WEEK_ENGLISH[i], time, i_year, i_month, day));
            }
            if ((i + i_start) == i_days) {
                // 月末
                // 月总结
                summaryArray.add(new Summary(Type.Month, Global.WEEK_CHINESS[i], Global.WEEK_ENGLISH[i], time, i_year, i_month, day));
                if (i_month == Global.MAX_MONTH) {
                    // 最后一个月，表示年末
                    // 年总结
                    summaryArray.add(new Summary(Type.Year, Global.WEEK_CHINESS[i], Global.WEEK_ENGLISH[i], time, i_year, i_month, day));
                }
            }
        }
        List<DBObject> summaryList = getSummaryData(s_uuid, date_start, date_end);

        for (DBObject object : summaryList) {
            Integer classify = DBObjectUtils.getInt(object, "classify") - 1;

            if (classify.equals(Type.Day.ordinal())) {
                object.put("type", Type.Day);
            } else if (classify.equals(Type.Week.ordinal())) {
                object.put("type", Type.Week);
            } else if (classify.equals(Type.Month.ordinal())) {
                object.put("type", Type.Month);
            } else if (classify.equals(Type.Year.ordinal())) {
                object.put("type", Type.Year);
            }

            for (Summary summary : summaryArray) {
                String date = DateUtils.dateToString((Date) object.get("deadtime"), DateUtils.DATE_FORMAT_DD);

                if (summary.getDate().equals(date) && summary.getType().equals(object.get("type"))) {

                    // 类型和时间相等，开始赋值操作
                    summary.setRead(DBObjectUtils.getInt(object, "aread"));
                    summary.setReadsum(DBObjectUtils.getInt(object, "readsum"));
                    String s_state = DBObjectUtils.getString(object, "state");
                    boolean share = "1".equals(DBObjectUtils.getString(object, "share")) ? true : false;
                    summary.setFinsh("1".equals(s_state) ? true : false);
                    summary.setDraft("0".equals(s_state) ? true : false);
                    summary.setWrite_id(DBObjectUtils.getString(object, "_id"));
                    summary.setShare(share);
                    summary.setReply(DBObjectUtils.getInt(object, "replayno"));

                    break;
                }
            }
        }

        return summaryArray;
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 根据写总结人，收总结人，总结阅读状态查询总结数量
     * @param sender:写总结人uuid数组
     * @param recieve：接收人的uuid
     * @param state：是否已读 0：未读 1：已读
     * @return 
     * @author helios
     * @createtime 2014-12-15
     */
    private long countSummary(String recieve, JSONArray sender, String state) {

        List<DBObject> conditionList = new ArrayList<DBObject>();
        DBObject conditionBean;

        for (int i = 0; i < sender.size(); i++) {

            conditionBean = new BasicDBObject();
            String uuid = sender.getString(i);
            conditionBean.put("uuid", uuid);//发送人

            //如果是查看未读，则添加条件，否则查看所有
            if ("0".equals(state)) {

                DBObject ele = new BasicDBObject();
                ele.put("state", state);
                ele.put("uuid", recieve);//接收人
                conditionBean.put("consignee", new BasicDBObject("$elemMatch", ele));//查看状态
            } else {

                conditionBean.put("consignee.uuid", recieve);//接收人的uuid
            }

            conditionBean.put("state", "1");//总结的状态, "0":保存为草稿 ；"1"：发送
            conditionList.add(conditionBean);
        }

        long count = commonDao.getCommonCount(TableName.SUMMARIZE_CONTENT, new BasicDBObject("$or", conditionList));

        return count;
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 
     * @param s_type  s_type:index；表示是刚进来时的加载,change:表示是手动切换年月
     * @param i_year
     * @param i_month
     * @param i_week
     * @createTime 2014-12-16
     * @since 1.0
     * @author Einstein
     * @return 返回总结数据JSONObject格式
     */
    public JSONObject getSummaryInfo(String s_uuid, String s_type, int i_year, int i_month, int i_week) {

        JSONObject json_result = new JSONObject();

        if ("index".equals(s_type) || "change".equals(s_type)) {

            if ("index".equals(s_type)) {

                // 首页加载，初始时用系统时间
                i_year = DateUtils.getYear(new Date());// 取系统年
                i_month = DateUtils.getMonth(new Date());// 取系统月
                int i_currentFirstMonday = DateUtils.firstMonday(i_year, i_month);// 取得当月第一个星期一是哪天
                int i_days = DateUtils.getDaysOfMonth(i_year, i_month);// 取得这个月总共有多少天

                /********************** 以下代码开始计算当前时间处在哪个周里面，以便动态的显示 ***********************/

                // 计算当前是在第几周内
                int i_currentDay = Integer.parseInt(DateUtils.dateToString(new Date(), "dd"));// 取得当前天
                int i_currentWeek = (int) Math.floor((i_currentDay - i_currentFirstMonday) * 1.0 / Global.DAYS_OF_WEEK) + 1;

                if (i_currentWeek == 0) {

                    // 等于0表示，当前天还不够当前第一个星期一的时间，所以需要显示上个月的数据，因为这个时间在上个月的最后一周里
                    // 需要显示在上个月的周数里
                    Date previousDate = DateUtils.previousMonth(new Date());// 取上个月
                    i_year = DateUtils.getYear(previousDate);// 取上月的年份
                    i_month = DateUtils.getMonth(previousDate);// 取上月的月份
                    i_days = DateUtils.getDaysOfMonth(i_year, i_month);// 取上月的天数
                    i_currentFirstMonday = DateUtils.firstMonday(i_year, i_month);// 取上月的第一个星期天是几号
                }

                /********************** 以上代码开始计算当前时间处在哪个周里面，以便动态的显示end **********************/

                // 首页加载
                int i_weeks;

                if ((i_days - i_currentFirstMonday) % Global.DAYS_OF_WEEK == 0) {

                    // 说明月末是星期一，所以也算一个星期
                    i_weeks = (int) (Math.ceil((i_days - i_currentFirstMonday) * 1.0 / Global.DAYS_OF_WEEK) + 1);
                } else {
                    i_weeks = (int) Math.ceil((i_days - i_currentFirstMonday) * 1.0 / Global.DAYS_OF_WEEK);
                }

                if (i_currentWeek == 0) {

                    // 等于0表示，当前天还不够当前第一个星期一的时间，所以需要显示上个月的数据，因为这个时间在上个月的最后一周里
                    // 设置当前周为上个月的最大周数
                    i_currentWeek = i_weeks;
                }
                json_result.put("year", i_year);
                json_result.put("month", i_month);
                json_result.put("weeks", i_weeks);
                json_result.put("currentWeek", i_currentWeek);
                json_result.put("data", getMonthDataByWeek(s_uuid, i_year, i_month, i_currentWeek, i_currentFirstMonday, i_days));
                return json_result;
            } else {

                // 是改变年月的，所以默认第1周
                int i_currentFirstMonday = DateUtils.firstMonday(i_year, i_month);// 这个月的第一个星期一是几号
                int i_days = DateUtils.getDaysOfMonth(i_year, i_month); // 这个月总共有多少天
                int i_weeks;// 总共有多少周

                if ((i_days - i_currentFirstMonday) % Global.DAYS_OF_WEEK == 0) {
                    // 说明月末是星期一，所以也算一个星期
                    i_weeks = (int) (Math.ceil((i_days - i_currentFirstMonday) * 1.0 / Global.DAYS_OF_WEEK) + 1);
                } else {
                    i_weeks = (int) Math.ceil((i_days - i_currentFirstMonday) * 1.0 / Global.DAYS_OF_WEEK);
                }
                json_result.put("year", i_year);
                json_result.put("month", i_month);
                json_result.put("weeks", i_weeks);
                json_result.put("currentWeek", 1);// 是改变年月的，所以默认第1周
                json_result.put("data", getMonthDataByWeek(s_uuid, i_year, i_month, 1, i_currentFirstMonday, i_days));
                return json_result;
            }
        } else {

            int i_currentFirstMonday = DateUtils.firstMonday(i_year, i_month);// //这个月的第一个星期一是几号
            int i_days = DateUtils.getDaysOfMonth(i_year, i_month); // 这个月总共有多少天
            json_result.put("data", getMonthDataByWeek(s_uuid, i_year, i_month, i_week, i_currentFirstMonday, i_days));
            return json_result;
        }
    }

    /*-------------------------------------------------------------------------------------------*/

    public boolean setread(HttpServletRequest request) {

        //获取参数
        String oid = RequestUtils.getString(request, "oid");
        JSONArray JSY_oid = JSONUtils.getJSONArray(oid);

        String uuid = (String) request.getSession().getAttribute("uuid");

        boolean flag = true;//返回值，默认为true
        DBObject DBO_condition;

        try {
            for (int i = 0, len = JSY_oid.size(); i < len; i++) {

                DBO_condition = new BasicDBObject();
                DBO_condition.put("oid", JSY_oid.getString(i));

                DBObject ele = new BasicDBObject();
                ele.put("state", "0");
                ele.put("uuid", uuid);
                DBO_condition.put("consignee", new BasicDBObject("$elemMatch", ele));//查看状态

                //修改状态为已读
                DBObject update = new BasicDBObject();
                update.put("consignee.$.state", "1");

                boolean b_flag = commonDao.updateCommon(TableNameConstant.T_SUMMARIZE_CONTENT, DBO_condition, update);

                if (b_flag) {

                    //将已阅人数+1
                    DBO_condition = new BasicDBObject();
                    DBO_condition.put("oid", JSY_oid.getString(i));

                    update = new BasicDBObject("aread", 1);
                }

                commonDao.updateInt(TableNameConstant.T_SUMMARIZE_CONTENT, DBO_condition, update);
            }
        } catch (Exception e) {
            flag = false;
            log.error(e.getLocalizedMessage(), e);
        }

        return flag;
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 根据时间段获取总结的数据
     * @param uuid
     * @param start
     * @param end
     * @return
     * author Einstein 2014-12-16
     */
    public List<DBObject> getSummaryData(String uuid, Date startDate, Date endDate) {

        //根据uuid 起始、结束时间查询工作总结表，获取是否完成、阅我、总人数、是否分享、回复人数、类型字段
        DBObject DBO_filedsBean = new BasicDBObject();

        DBO_filedsBean.put("_id", 1);
        DBO_filedsBean.put("state", 1);
        DBO_filedsBean.put("aread", 1);
        DBO_filedsBean.put("readsum", 1);
        DBO_filedsBean.put("share", 1);
        DBO_filedsBean.put("replayno", 1);
        DBO_filedsBean.put("classify", 1);
        DBO_filedsBean.put("deadtime", 1);
        DBO_filedsBean.put("content", 1);

        BasicDBObject query1 = new BasicDBObject();
        query1.put("deadtime", new BasicDBObject("$gte", startDate).append("$lte", endDate));

        BasicDBObject query2 = new BasicDBObject();
        query2.put("deadtime", new BasicDBObject("$lte", startDate));
        query2.put("deadtime", new BasicDBObject("$gte", startDate));

        BasicDBList all = new BasicDBList();
        all.add(query1);
        all.add(query2);

        BasicDBObject condition = new BasicDBObject();
        condition.put("$or", all);
        condition.put("uuid", uuid);

        return commonDao.searchLessCommon(TableName.SUMMARIZE_CONTENT, condition, DBO_filedsBean, new BasicDBObject("deadtime", 1));
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 跟据传入的公司编号、部门uuid查出当前人所在公司的所有员工
     * @param request companyno:公司编号
     * 					uuid：部门uuid
     * @param response
     * @author helios
     * @createtime 2014-12-15
     */
    public List<DBObject> getPeople(HttpServletRequest request) {

        String uuid = RequestUtils.getString(request, "uuid");//部门uuid
        uuid = uuid == null ? "" : uuid;
        String companyno = RequestUtils.getString(request, "companyno");//公司编号"23292303683324"
        WebService ws = new WebService();

        ws.setURL("/businessplat/services/CcAndroidService");
        ws.setMethodName("getOrganization");
        ws.setProperty(new String[] { companyno, uuid });
        String result = ws.getString();
        JSONArray peopleArr = JSONUtils.getJSONArray(result);
        List<DBObject> retList = new ArrayList<DBObject>();

        //获取ccno、总人数、部门编号、是否为分组、姓名、性别、uuid
        DBObject peopleBean;
        for (int i = 0; i < peopleArr.size(); i++) {

            JSONObject jsonObj = JSONUtils.getJsonObject(peopleArr.getString(i));

            peopleBean = new BasicDBObject();
            peopleBean.put("ccno", JSONUtils.getString(jsonObj, "ccno"));
            peopleBean.put("count", JSONUtils.getString(jsonObj, "count"));
            peopleBean.put("frameuuid", JSONUtils.getString(jsonObj, "frameuuid"));
            peopleBean.put("group", JSONUtils.getString(jsonObj, "group"));
            peopleBean.put("name", JSONUtils.getString(jsonObj, "name"));
            peopleBean.put("sex", JSONUtils.getString(jsonObj, "sex"));
            peopleBean.put("uuid", JSONUtils.getString(jsonObj, "uuid"));

            retList.add(peopleBean);
        }

        return retList;
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 根据条件读取工作总结
     * @param request
     *     	s_id：看总结的_id
     * @author 易泉 2014-12-20
     */
    public DBObject queryByid(HttpServletRequest request) {

        String s_id = RequestUtils.getString(request, "s_id");
        //查询条件
        DBObject DBO_conditionBran = new BasicDBObject();
        DBO_conditionBran.put("_id", new ObjectId(s_id));

        //返回对象
        DBObject DBO_less = new BasicDBObject();
        DBO_less.put("content", 1);

        //调用方法
        DBObject DBO_content = commonDao.searchLessCommonOne(TableNameConstant.T_SUMMARIZE_CONTENT, DBO_conditionBran, DBO_less);
        return DBO_content;
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 根据条件读取工作总结
     * @param request
     *     	uuid：看总结人的uuid
     * 		state：状态 "0":未读 ,"1":所有
     * 		groupname:分组名
     * 		pageSize:每页大小
     * 		pageNo:当前页
     * 		version：版本号，最新总结的创建时间毫米数
     * @param response	返回符合条件的工作总结
     * @author helios 2014-12-13
     */
    public String readSummary(HttpServletRequest request) {

        //获取页面参数 uuid、要查看的状态、分组名、当前页码、每页大小
        String s_uuid = RequestUtils.getString(request, "uuid");
        if (StringUtils.isBlank(s_uuid) || "null".equals(s_uuid)) {
            s_uuid = (String) request.getSession().getAttribute("uuid");
        }

        String s_state = RequestUtils.getString(request, "state");
        String groupname = RequestUtils.getString(request, "groupname");
        int pageNo = RequestUtils.getInt(request, "pageNo");
        int perPageCount = RequestUtils.getInt(request, "pageSize");
        long version = RequestUtils.getLong(request, "version");

        DBObject conditonBean = new BasicDBObject();

        //根据用户uuid、分组名查找分组表
        conditonBean.put("uuid", s_uuid);
        conditonBean.put("groupname", groupname);
        DBObject groupBean = commonDao.searchCommonOne(TableName.SUMMARIZE_GROUP, conditonBean);

        //获取分组下的所有人的uuid
        JSONArray UUIDArr = DBObjectUtils.getJSONArray(groupBean, "group");
        List<DBObject> conditionList = new ArrayList<DBObject>();//条件集合

        for (int i = 0; i < UUIDArr.size(); i++) {
            //拼接查询条件：发送人uuid、接收人uuid、查看状态、总结状态
            String sendUUID = UUIDArr.getString(i);
            conditonBean = new BasicDBObject();
            conditonBean.put("uuid", sendUUID);//发送人uuid

            //如果是查看未读，则添加条件，否则查看所有
            if ("0".equals(s_state)) {
                DBObject ele = new BasicDBObject();
                ele.put("state", s_state);
                ele.put("uuid", s_uuid);
                conditonBean.put("consignee", new BasicDBObject("$elemMatch", ele));//查看状态
            } else {
                conditonBean.put("consignee.uuid", s_uuid);//接收人的uuid
            }
            conditonBean.put("state", "1");//总结的状态, "0":保存为草稿 ；"1"：发送
            conditionList.add(conditonBean);
        }

        List<DBObject> retList = new ArrayList<DBObject>();

        //如果没有数据，则返回一个空的集合,防止查询时报异常
        if (conditionList == null || conditionList.size() < 1) {

            return retList.toString();
        }

        List<DBObject> conditions = new ArrayList<DBObject>();
        conditions.add(new BasicDBObject("$or", conditionList));

        //获取参数，"1":取版本号之前的，否则，取版本号之后的数据 
        String s_flag = RequestUtils.getString(request, "flag");

        if ("1".equals(s_flag)) {
            conditions.add(new BasicDBObject("version", new BasicDBObject("$lt", version)));
        } else {
            conditions.add(new BasicDBObject("version", new BasicDBObject("$gt", version)));
        }

        JSONObject summaryData = (JSONObject) commonDao.searchCommonPage(TableName.SUMMARIZE_CONTENT, new BasicDBObject("$and", conditions), new BasicDBObject("time", -1), pageNo, perPageCount);
        JSONArray summaryArr = JSONUtils.getJSONArray(summaryData, "data");

        for (int i = 0; i < summaryArr.size(); i++) {

            JSONObject summary = summaryArr.getJSONObject(i);
            DBObject summaryBean = (DBObject) JSON.parse(summary.toString());
            DBObject retBean = new BasicDBObject();

            Date ctime = DBObjectUtils.getDate(summaryBean, "time");

            //获取总结编号、类型、标题、发送人uuid、发送人姓名、发送时间、是否已读、内容详情、版本号(创建总结时间毫米数)
            retBean.put("oid", DBObjectUtils.getString(summaryBean, "oid"));
            retBean.put("type", DBObjectUtils.getString(summaryBean, "classify"));
            retBean.put("title", DBObjectUtils.getString(summaryBean, "title"));
            retBean.put("uuid", DBObjectUtils.getString(summaryBean, "uuid"));
            retBean.put("name", DBObjectUtils.getString(summaryBean, "name"));
            retBean.put("ctime", DateUtils.dateToString(ctime, DateUtils.DATE_FORMAT_SS));
            retBean.put("version", ctime.getTime());

            //阅读状态
            List<DBObject> consignees = DBObjectUtils.getList(summaryBean, "consignee");
            for (DBObject consigneeBean : consignees) {
                String _uuid = DBObjectUtils.getString(consigneeBean, "uuid");
                if (s_uuid.equals(_uuid)) {
                    retBean.put("state", DBObjectUtils.getString(consigneeBean, "state"));
                    break;
                }
            }

            //总结内容
            retBean.put("details", DBObjectUtils.getDBList(summaryBean, "content"));
            retList.add(retBean);
        }

        return retList.toString();
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 查看这篇总结的 阅读情况 接口
     * @author阳二华  2014-12-16
     * @param request	year：总结截止日期的年份
     * 					month：总结的截止的月份
     *                  day：总结截止的日子
     *                  uuid：这个人的uuid
     *                  classify ：  1日总结 2周总结 3月总结
     */
    public String selectAllIfRead(HttpServletRequest request) {

        // 年
        String year = RequestUtils.getString(request, "year");

        // 月
        String month = RequestUtils.getString(request, "month");

        // 日
        String day = RequestUtils.getString(request, "day");

        // 1日总结 2周总结 3月总结
        String classify = RequestUtils.getString(request, "classify");

        // 1日总结 2周总结 3月总结
        String uuid = (String) request.getSession().getAttribute("uuid");
        //        if (StringUtils.isBlank(uuid) || "null".equals(uuid)) {
        //            uuid =
        //        }

        // 条件
        DBObject conditionBean = new BasicDBObject();
        conditionBean.put("uuid", uuid);
        conditionBean.put("classify", classify);

        //页面截止日期
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, Integer.valueOf(year));
        cal.set(Calendar.MONTH, Integer.valueOf(month) - 1);
        cal.set(Calendar.DAY_OF_MONTH, Integer.valueOf(day));
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        Date dendtime = new Date(cal.getTimeInMillis());

        conditionBean.put("deadtime", dendtime);

        //字段
        DBObject DBO_less = new BasicDBObject();
        DBO_less.put("consignee", 1);
        DBO_less.put("deadtime", 1);

        DBObject obj = commonDao.searchLessCommonOne(TableNameConstant.T_SUMMARIZE_CONTENT, conditionBean, DBO_less);

        List<DBObject> readArr = DBObjectUtils.getList(obj, "consignee");
        for (int i = 0; i < readArr.size(); i++) {
            DBObject replyArrObj = readArr.get(i);
            Date date = DBObjectUtils.getDate(replyArrObj, "time");
            String time = DateUtils.dateToString(date, DateUtils.DATE_FORMAT_DD);
            Date todayDate = new Date();
            String today = DateUtils.dateToString(todayDate, DateUtils.DATE_FORMAT_DD);
            if (time == today) {
                time = DateUtils.dateToString(date, "HH:mm");
            }

            replyArrObj.put("time", time);
        }
        obj.put("consignee", readArr);

        return obj.toString();

    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 回复别人给我的评价，做更新。
     * 
     * @author阳二华  2014-12-16
     * @param request	uuid：写回复人uuid
     * 					_id：Summarize_replay表的id
     *                 value回复的内容
     * @param response	ture成功 false失败
     */
    public String updateReplyOthers(HttpServletRequest request) {

        Boolean flag;
        //Summarize_replay表的id
        String S_idString = RequestUtils.getString(request, "_id");
        //写这个回复人的uuid
        String s_uuid = RequestUtils.getString(request, "uuid");
        //回复的内容
        String s_value = RequestUtils.getString(request, "value");

        ObjectId _id = new ObjectId(S_idString);

        DBObject dataObject = new BasicDBObject();
        dataObject.put("uuid", s_uuid);

        //抽取写这个回复人的人信息
        DBObject objReciever = commonDao.searchCommonOne(TableNameConstant.T_SUMMARIZE_RECIEVER, dataObject);
        //写回复人的名字和ccno
        String s_name = DBObjectUtils.getString(objReciever, "name");
        String s_ccno = DBObjectUtils.getString(objReciever, "ccno");

        //条件
        DBObject updateconditionBean = new BasicDBObject();
        updateconditionBean.put("_id", _id);

        //更新的数据
        DBObject updateBean = new BasicDBObject();
        updateBean.put("name", s_name);
        updateBean.put("ccno", s_ccno);
        updateBean.put("uuid", s_uuid);
        updateBean.put("value", s_value);
        updateBean.put("rtime", new Date());

        DBObject updateBeanResult = new BasicDBObject();
        updateBeanResult.put("againReplay", updateBean);

        flag = commonDao.updateCommonPush(TableNameConstant.T_SUMMARIZE_REPLAY, updateconditionBean, updateBeanResult);

        //将每一次的修改添加修改时间
        updateBeanResult = new BasicDBObject();
        updateBeanResult.put("replytime", new Date());
        commonDao.updateCommon(TableNameConstant.T_SUMMARIZE_REPLAY, updateconditionBean, updateBeanResult);

        //        if (flag) {
        //            //总结的回复数+1
        //            DBObject DBO_condition = new BasicDBObject("_id", _id);
        //            DBObject DBO_update = new BasicDBObject("replayno", 1);
        //
        //            flag = commonDao.updateInt(TableName.SUMMARIZE_CONTENT, DBO_condition, DBO_update);
        //        }

        return flag.toString();
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 第一次回复
     * @param request	param：回复的具体内容
     * @return			操作结果 成功：1，失败 0
     * @author heliso
     * @createtime 2014-12-15
     */
    public String firstReply(HttpServletRequest request) {

        //获取页面参数
        String param = RequestUtils.getString(request, "param");
        JSONObject paramObj = JSONUtils.getJsonObject(param);

        DBObject insertBean = new BasicDBObject();//要插入的数据

        //获取总结编号、回复人编号、回复内容、回复哪一条
        String oid = JSONUtils.getString(paramObj, "oid");

        String replayno = JSONUtils.getString(paramObj, "replayno");

        if (StringUtils.isBlank(replayno) || "null".equals(replayno)) {
            replayno = (String) request.getSession().getAttribute("ccno");
        }

        String replayname = DBObjectUtils.getString(paramObj, "replayname");
        if (StringUtils.isBlank(replayname) || "null".equals(replayname)) {
            replayname = (String) request.getSession().getAttribute("realname");
        }

        String content = JSONUtils.getString(paramObj, "content");
        JSONArray towards = JSONUtils.getJSONArray(paramObj, "towards");

        //根据总结编号查询总结表
        DBObject conditionBran = new BasicDBObject("oid", oid);
        DBObject summary = commonDao.searchCommonOne(TableName.SUMMARIZE_CONTENT, conditionBran);

        //获取发送人ccno、uuid、姓名、总结类型、总结时间
        String ccno = DBObjectUtils.getString(summary, "ccno");
        String uuid = DBObjectUtils.getString(summary, "uuid");
        String name = DBObjectUtils.getString(summary, "name");
        String type = DBObjectUtils.getString(summary, "type");
        Date ztime = DBObjectUtils.getDate(summary, "time");

        Date time = new Date();//回复时间

        //拼接要插入的数据
        insertBean.put("oid", oid);
        insertBean.put("ccno", ccno);
        insertBean.put("uuid", uuid);
        insertBean.put("name", name);
        insertBean.put("replayno", replayno);
        insertBean.put("replayname", replayname);
        insertBean.put("content", content);
        insertBean.put("time", time);
        insertBean.put("towards", towards);
        insertBean.put("ztime", ztime);
        insertBean.put("type", type);

        String ret = "1";
        //添加操作
        try {
            commonDao.insertCommon(TableName.SUMMARIZE_REPLAY, insertBean);
        } catch (Exception e) {
            log.error(e.getLocalizedMessage(), e);
            ret = "0";
        }

        //总结的回复数+1
        DBObject DBO_condition = new BasicDBObject("oid", oid);
        DBObject DBO_update = new BasicDBObject("replayno", 1);

        boolean flag = commonDao.updateInt(TableName.SUMMARIZE_CONTENT, DBO_condition, DBO_update);

        return (ret.equals("1") && flag) ? "1" : "0";
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 阳二华 2014-12-13   获取工作总结模板
     * 
     * @param request
     *            写总结人的uuid
     * @param response
     *            获取到的工作模板
     */
    public String getTemplate(HttpServletRequest request) {

        //周，日，月总结
        String type = RequestUtils.getString(request, "type");

        // 条件是等于type
        DBObject conditionBean = new BasicDBObject();
        conditionBean.put("type", type);

        // 字段名
        DBObject less = new BasicDBObject();
        less.put("content", 1);

        Object obj = commonDao.searchLessCommonOne(TableNameConstant.T_SUMMARIZE_TEMPLATE, conditionBean, less);

        JSONObject jsonObject = JSONObject.fromObject(obj);

        return jsonObject.toString();

    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 阳二华 2014-12-13 添加总结 
     * 
     * @param dbObject
     * @author Einstein Ron()
     */
    public String addSumData(HttpServletRequest request) {

        Boolean s_flag = false;//返回值
        String s_ifwrited = RequestUtils.getString(request, "ifwrited");//是否是更新
        String s_content = RequestUtils.getString(request, "content");//内容   
        s_content = StringUtils.toHtml(s_content); //内容转义存数据库
        String s_state = RequestUtils.getString(request, "state");// 存草稿还是保存
        String s_saveactully = RequestUtils.getString(request, "saveactully");//是否是自动保存

        if ("1".endsWith(s_ifwrited)) {
            String s_write_id = RequestUtils.getString(request, "write_id");// 更新得到主键
            s_content = s_content.substring(0, s_content.length() - 1);//内容拼接正确格式
            s_content = s_content + "]";

            //内容转换对象
            JSONArray JSY_obj = JSONArray.fromObject(s_content);
            DBObject DBO_data = new BasicDBObject();
            DBO_data.put("content", JSY_obj);

            ObjectId _id = new ObjectId(s_write_id); //把主键转换成objectid对象

            //更新条件
            DBObject DBO_updateCondition = new BasicDBObject();
            DBO_updateCondition.put("_id", _id);

            if ("1".endsWith(s_saveactully)) {
                //此时是自动保存，不管他的状态是什么
            } else {
                //更新的内容 保存还是存草稿
                DBO_data.put("state", s_state);
            }

            //把已读总数改成未读
            DBO_data.put("aread", 0);

            //时间
            DBO_data.put("time", new Date());
            DBO_data.put("version", DBObjectUtils.getDate(DBO_data, "time").getTime());//修改版本号

            //把所有接收人 已经读过，改成未读

            //            DBO_data.put("consignee.$.state", "0");
            String s_uuid = (String) request.getSession().getAttribute("uuid"); //写总结人的uuid    
            //查出接收人
            DBObject DBO_reciever = commonDao.searchCommonOne(TableNameConstant.T_SUMMARIZE_RECIEVER, new BasicDBObject("uuid", s_uuid));
            //接收人信息
            List<DBObject> l_reciever = DBObjectUtils.getList(DBO_reciever, "reciever");

            //接收人信息
            for (int i = 0; i < l_reciever.size(); i++) {
                DBObject recieverDbObject = l_reciever.get(i);
                recieverDbObject.put("state", "0");
                recieverDbObject.put("time", new Date());
            }
            DBO_data.put("consignee", l_reciever);
            DBO_data.put("push", "all");
            s_flag = commonDao.updateCommon(TableNameConstant.T_SUMMARIZE_CONTENT, DBO_updateCondition, DBO_data);

            //如果是自动保存，然后返回主键
            if ("1".endsWith(s_saveactully)) {
                //return s_write_id.toString();

                DBObject backDbObject = new BasicDBObject();
                backDbObject.put("backid", s_write_id);

                JSONObject jsonObject = JSONObject.fromObject(backDbObject);

                return jsonObject.toString();
            } else {
                return s_flag.toString();
            }

        } else {

            String s_uuid = (String) request.getSession().getAttribute("uuid"); //写总结人的uuid             
            String s_type = RequestUtils.getString(request, "type"); //日，周，年，月，类型
            String s_classify = RequestUtils.getString(request, "classify");//0 日，1 周，3 年，2 月，类型          
            String s_week = RequestUtils.getString(request, "week");//周星期一
            String s_year = RequestUtils.getString(request, "year"); //年        
            String s_month = RequestUtils.getString(request, "month"); //月           
            String s_day = RequestUtils.getString(request, "day");//日

            //截止日期
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.YEAR, Integer.valueOf(s_year));
            cal.set(Calendar.MONTH, Integer.valueOf(s_month) - 1);
            cal.set(Calendar.DAY_OF_MONTH, Integer.valueOf(s_day));
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);
            Date date = new Date(cal.getTimeInMillis());

            s_content = s_content.substring(0, s_content.length() - 1);
            s_content = s_content + "]";

            //内容
            JSONArray JSO_obj = JSONArray.fromObject(s_content);

            DBObject DBO_data = new BasicDBObject();
            DBO_data.put("uuid", s_uuid);

            //查出接收人
            DBObject DBO_reciever = commonDao.searchCommonOne(TableNameConstant.T_SUMMARIZE_RECIEVER, DBO_data);

            //接收人名字和ccno
            String s_name = DBObjectUtils.getString(DBO_reciever, "name");
            String s_ccno = DBObjectUtils.getString(DBO_reciever, "ccno");

            //拼接总结title
            String s_title = (new StringBuffer().append(s_name).append(s_month).append("月").append(s_day).append("日").append(s_type)).toString();

            //接收人信息
            List<DBObject> l_reciever = DBObjectUtils.getList(DBO_reciever, "reciever");

            //接收人信息
            for (int i = 0; i < l_reciever.size(); i++) {
                DBObject recieverDbObject = l_reciever.get(i);
                recieverDbObject.put("state", "0");
                recieverDbObject.put("time", new Date());
            }

            DBO_data.put("name", s_name);
            DBO_data.put("ccno", s_ccno);
            DBO_data.put("title", s_title);
            DBO_data.put("consignee", l_reciever);
            DBO_data.put("deadtime", date);
            DBO_data.put("type", s_type);

            DBO_data.put("classify", s_classify);
            DBO_data.put("state", s_state);
            DBO_data.put("week", s_week);
            DBO_data.put("content", JSO_obj);

            //阅读总数
            DBO_data.put("readsum", l_reciever.size());
            DBO_data.put("aread", 0);
            DBO_data.put("share", "0");
            DBO_data.put("replayno", 0);

            //时间
            DBO_data.put("time", new Date());
            DBO_data.put("oid", StringUtils.getUniqueString());
            DBO_data.put("version", DBObjectUtils.getDate(DBO_data, "time").getTime());//版本号，创建日期的毫秒数
            DBO_data.put("push", "some");
            DBO_data.put("creattime", new Date());// 创建的时间
            s_flag = commonDao.insertCommon(TableNameConstant.T_SUMMARIZE_CONTENT, DBO_data);

            //如果是自动保存 返回id
            if ("1".endsWith(s_saveactully)) {

                DBObject conditionBran = new BasicDBObject();
                conditionBran.put("deadtime", date);
                conditionBran.put("type", s_type);
                conditionBran.put("classify", s_classify);
                conditionBran.put("uuid", s_uuid);

                DBObject lessBean = new BasicDBObject();
                lessBean.put("_id", 1);

                DBObject sidDbObject = commonDao.searchLessCommonOne(TableNameConstant.T_SUMMARIZE_CONTENT, conditionBran, lessBean);
                String sidString = DBObjectUtils.getString(sidDbObject, "_id");

                DBObject backDbObject = new BasicDBObject();
                backDbObject.put("backid", sidString);

                JSONObject jsonObject = JSONObject.fromObject(backDbObject);

                return jsonObject.toString();

            } else {

                return s_flag.toString();
            }
        }
    }

    /*-------------------------------------------------------------------------------------------*/
    /**
     *	我回复的
     * @param uuid //拿到写总结人的uuid
     * @param pageNo //当前页数
     * @param perPageCount //总记录数
     * @param meRyPid 我回复的功能ID
     * @param reduce 页面显示的条数
     * author 易泉 2014-12-13 
     */
    public String meReply(HttpServletRequest request) {

        //拿到登录人的uuid
        String s_uuid = request.getSession().getAttribute("uuid").toString();

        //拿到登录人的ccno
        String s_ccno = request.getSession().getAttribute("ccno").toString();

        //当前页数
        int i_pageNo = RequestUtils.getInt(request, "pageNo");

        //每页记录数
        int i_perPageCount = RequestUtils.getInt(request, "perPageCount");

        //功能点参数ryMePid
        String s_meRyPid = RequestUtils.getString(request, "meRyPid");

        //页面显示的条数
        int i_reduce = RequestUtils.getInt(request, "reduce");

        //查询条件
        //        DBObject DBO_conditionBean = new BasicDBObject();

        DBObject DBO_condition1 = new BasicDBObject();
        DBO_condition1.put("replayno", s_ccno);

        //        DBObject DBO_condition2 = new BasicDBObject();
        //        DBO_condition2.put("againReplay.ccno", s_ccno);

        //        BasicDBList dbList = new BasicDBList();
        //        dbList.add(DBO_condition1);
        //        dbList.add(DBO_condition2);

        //        DBO_conditionBean.put("$or", dbList);

        //排序条件
        DBObject DBO_orderBy = new BasicDBObject();
        DBO_orderBy.put("time", -1);

        //调用方法分页排序查找
        List<DBObject> l_replyList = commonDao.searchLessCommon(TableNameConstant.T_SUMMARIZE_REPLAY, DBO_condition1, i_pageNo, i_perPageCount, DBO_orderBy);

        if (i_reduce > 0) {
            //调用减少功能消息条数
            ReduceCountUtils.reduceMsgCount(s_uuid, s_meRyPid, i_reduce);
        }

        String s_result = ReplayUtils.getData(l_replyList);

        return s_result;
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     *	回复我的
     * @param ccno //拿到登录人的CCNO号
     * @param pageNo //当前页数
     * @param perPageCount //总记录数
     * @param ryMePid 回复我的功能ID
     * @param reduce
     * @author 易泉 2014-12-13 
     */
    public String replyMe(HttpServletRequest request) {

        //拿到登录人的uuid
        String s_uuid = request.getSession().getAttribute("uuid").toString();
        //        String s_uuid = "0d12e034-4415-413b-9c38-3357d488d834";

        //当前页数
        int i_pageNo = RequestUtils.getInt(request, "pageNo");

        //总记录数
        int i_perPageCount = RequestUtils.getInt(request, "perPageCount");

        //功能点参数ryMePid
        String s_ryMePid = RequestUtils.getString(request, "ryMePid");

        int i_reduce = RequestUtils.getInt(request, "reduce");

        //查询条件
        //        DBObject DBO_conditionBean = new BasicDBObject();

        DBObject DBO_condition1 = new BasicDBObject();
        DBO_condition1.put("uuid", s_uuid);

        //        DBObject DBO_condition2 = new BasicDBObject();
        //        DBO_condition2.put("againReplay.uuid", s_uuid);

        //        BasicDBList dbList = new BasicDBList();
        //        dbList.add(DBO_condition1);
        //        dbList.add(DBO_condition2);

        //        DBO_conditionBean.put("$or", dbList);

        //排序条件
        DBObject DBO_orderBy = new BasicDBObject();
        DBO_orderBy.put("time", -1);

        //调用方法分页排序查找
        List<DBObject> l_replyList = commonDao.searchLessCommon(TableNameConstant.T_SUMMARIZE_REPLAY, DBO_condition1, i_pageNo, i_perPageCount, DBO_orderBy);

        if (i_reduce > 0) {
            //调用减少功能消息条数
            ReduceCountUtils.reduceMsgCount(s_uuid, s_ryMePid, i_reduce);
        }

        //进行解析返回数据
        String s_result = ReplayUtils.getData(l_replyList);

        return s_result;
    }

    /*-------------------------------------------------------------------------------------------*/
    /**
     *	回复页面的回复我的总条数 replyMeCount
     *	回复页面的我回复的总条数 meReplyCount
     * @param uuid //拿到登录人的UUID
     * @param 回复我的  功能点参数ryMePid
     * @param 我回复的  功能点参数meRyPid
     * @author 易泉 2014-12-13 
     */
    public String replyCount(HttpServletRequest request) {

        //拿到登录人的uuid 
        String s_uuid = request.getSession().getAttribute("uuid").toString();

        //回复我的功能点的ID
        String s_ryMePid = RequestUtils.getString(request, "ryMePid");

        //我回复的功能点的ID
        String s_meRyPid = RequestUtils.getString(request, "meRyPid");

        //回复我的查询条件
        DBObject DBO_conditionBean1 = new BasicDBObject();
        DBO_conditionBean1.put("uuid", s_uuid);
        DBO_conditionBean1.put("pid", s_ryMePid);

        //返回特定的字段
        DBObject DBO_less = new BasicDBObject();
        DBO_less.put("count", 1);

        //调用方法  拿到回复我的条数
        DBObject DBO_replyMeCount = commonDao.searchLessCommonOne(TableName.T_WORK, DBO_conditionBean1, DBO_less);
        if (DBO_replyMeCount != null) {
            DBO_replyMeCount.removeField("_id");
        }

        //我回复的查询条件
        DBObject DBO_conditionBean2 = new BasicDBObject();
        DBO_conditionBean2.put("uuid", s_uuid);
        DBO_conditionBean2.put("pid", s_meRyPid);

        //调用方法  拿到我回复的条数
        DBObject DBO_meReplyCount = commonDao.searchLessCommonOne(TableName.T_WORK, DBO_conditionBean2, DBO_less);

        if (DBO_meReplyCount != null) {
            DBO_meReplyCount.removeField("_id");
        }

        JSONObject JSY_obj = new JSONObject();

        if (DBO_replyMeCount != null) {
            JSY_obj.put("replyMeCount", DBO_replyMeCount);
        } else {
            JSY_obj.put("replyMeCount", 0);
        }
        if (DBO_meReplyCount != null) {
            JSY_obj.put("meReplyCount", DBO_meReplyCount);
        } else {
            JSY_obj.put("meReplyCount", 0);
        }

        return JSY_obj.toString();
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 获得某总结的所有回复内容
     * @param request
     *              ccno操作人的ccno
     *              _id 总结的唯一id
     * @param response
     * @author DK
     */
    public String getReplays(HttpServletRequest request) {

        int pageCount = 0;
        int pageno = 0;

        //获取分页查询的数据
        String s_perPageCount = RequestUtils.getString(request, "perPageCount");//显示多少条
        String s_pageNo = RequestUtils.getString(request, "pageNo");//第几页

        if (s_perPageCount != null && s_pageNo != null) {

            pageCount = StringUtils.stringToInt(s_perPageCount);
            pageno = StringUtils.stringToInt(s_pageNo);
        }

        String s_ccno = RequestUtils.getString(request, "ccno");//ccno	
        String s_id = RequestUtils.getString(request, "s_id");//总结的唯一id

        DBObject condition = new BasicDBObject();
        condition.put("ccno", s_ccno);

        ObjectId _id = new ObjectId(s_id);
        condition.put("_id", _id);

        //数据库操作
        List<DBObject> dataArray = commonDao.searchLessCommon(TableNameConstant.T_SUMMARIZE_REPLAY, condition, pageno, pageCount, new BasicDBObject("time", -1));

        //解析数据
        String result = ReplayUtils.getData(dataArray);

        return result.toString();
    }

    /*-------------------------------------------------------------------------------------------*/

    /**
     * 获取分组信息
     * @param request 要查看的状态 0：未读 1：所有
     * @author helios
     * @createtime 2014-12-15
     */
    public List<DBObject> groupList(HttpServletRequest request) {

        //获取页面参数
        String s_uuid = RequestUtils.getString(request, "uuid");
        if (StringUtils.isBlank(s_uuid) || "null".equals(s_uuid)) {
            s_uuid = (String) request.getSession().getAttribute("uuid");
        }
        String s_state = RequestUtils.getString(request, "state");

        //根据当前人的uuid查找分组表，获取分组信息
        DBObject conditonData = new BasicDBObject();
        conditonData.put("uuid", s_uuid);

        //按是否置顶、修改时间排序，降序
        List<DBObject> groupList = commonDao.searchCommon(TableName.SUMMARIZE_GROUP, conditonData, new BasicDBObject("putmost", -1).append("time", -1));

        List<DBObject> l_retList = new ArrayList<DBObject>();//要返回的数据集合

        DBObject retBean;
        for (DBObject groupBean : groupList) {
            retBean = new BasicDBObject();

            //将分组名、分组下的所有人数、是否置顶保存到要返回的数据中
            JSONArray JSY_UUIDArr = DBObjectUtils.getJSONArray(groupBean, "group");
            retBean.put("groupname", DBObjectUtils.getString(groupBean, "groupname"));
            retBean.put("count", this.countSummary(s_uuid, JSY_UUIDArr, s_state));
            retBean.put("putmost", DBObjectUtils.getString(groupBean, "putmost"));
            l_retList.add(retBean);
        }

        return l_retList;
    }

    /*-------------------------------------------------------------------------------------------*/
    /**
     * 
     * @param request 参数：无 从session中获取当前登录人的uuid
     * @param response 返回登录人的接收人uuid,ccno,name
     * @author Einstein
     */
    public List<DBObject> getReciever(HttpServletRequest request) {

        String s_uuid = RequestUtils.getString(request, "uuid");
        if (StringUtils.isBlank(s_uuid) || "null".equals(s_uuid)) {
            s_uuid = (String) request.getSession().getAttribute("uuid");
        }
        int i_year = RequestUtils.getInt(request, "year");//年
        int i_month = RequestUtils.getInt(request, "month");//月
        int i_day = RequestUtils.getInt(request, "day");
        String s_classify = RequestUtils.getString(request, "classify");
        DBObject condition = new BasicDBObject();
        condition.put("deadtime", DateUtils.getTime(i_year, i_month, i_day));
        condition.put("uuid", s_uuid);
        condition.put("classify", s_classify);
        //获取接收人
        DBObject DBO_content = commonDao.searchCommonOne(TableNameConstant.T_SUMMARIZE_CONTENT, condition);
        if (DBO_content == null) {
            return null;
        }
        List<DBObject> l_reciever = DBObjectUtils.getList(DBO_content, "consignee");
        if ("all".equals(DBO_content.get("push"))) {
            List<DBObject> l_reciever_some = new ArrayList<DBObject>();
            for (DBObject reciever : l_reciever) {
                if ("1".equals(reciever.get("state"))) {
                    l_reciever_some.add(reciever);
                }
            }
            return l_reciever_some;
        }
        return l_reciever;
    }

    /**
     * 初始化版本号
     * @author helios
     * @createtime 2015-1-3
     * @since 1.0
     */
    public void initVersion() {

        List<DBObject> l_summary = commonDao.searchCommon(TableNameConstant.T_SUMMARIZE_CONTENT, new BasicDBObject("version", null));

        for (DBObject summaryBean : l_summary) {

            Date ctime = DBObjectUtils.getDate(summaryBean, "time");
            long version = ctime.getTime();
            String oid = DBObjectUtils.getString(summaryBean, "oid");

            commonDao.updateCommon(TableNameConstant.T_SUMMARIZE_CONTENT, new BasicDBObject("oid", oid), new BasicDBObject("version", version));
        }
    }

    /*-------------------------------------------------------------------------------------------*/
    /**
     * 获取总结报表
     * @param request 日期，总结类型
     * @author Dimon
     * @createtime 2015-02-26
     */
    public JSONObject getSumCount(HttpServletRequest request) {

        JSONObject result = new JSONObject(); //返回值
        //获取页面参数
        String startStr = RequestUtils.getString(request, "date");
        String classify = RequestUtils.getString(request, "classfy");

        String[] startStrs = startStr.split("-");
        String startStr2 = startStrs[1] + "月" + startStrs[2] + "日";

        DateUtils.stringToDate(startStr, DateUtils.DATE_FORMAT_DD);
        Date date_start = DateUtils.getStartDate(DateUtils.stringToDate(startStr, DateUtils.DATE_FORMAT_DD));
        Date date_end = DateUtils.getDayOfAfterDays(date_start, 1);

        //时间大于当天00：00：00小于下一天的00：00：00，且状态为已发送
        DBObject conditonData = new BasicDBObject();

        BasicDBObject query = new BasicDBObject();
        query.put("$gte", date_start);//>=
        query.put("$lte", date_end);//<=

        conditonData.put("creattime", query);
        conditonData.put("state", "1");
        conditonData.put("classify", classify);

        //模糊查询需要使用的Pattern对象（关键）  
        Pattern pattern = Pattern.compile(startStr2, Pattern.CASE_INSENSITIVE);
        conditonData.put("title", pattern);
        //返回字段
        DBObject alreadyLess = new BasicDBObject();
        alreadyLess.put("uuid", 1);
        alreadyLess.put("title", 1);
        alreadyLess.put("creattime", 1);
        alreadyLess.put("name", 1);
        //当天提交的总结列表
        List<DBObject> alreadySumList = commonDao.searchLessCommon(TableName.SUMMARIZE_CONTENT, conditonData, alreadyLess);
        int alreadyCount = alreadySumList.size();

        //应提交总结的人列表
        DBObject recieverLess = new BasicDBObject();
        recieverLess.put("uuid", 1);
        recieverLess.put("name", 1);
        List<DBObject> recieverSumList = commonDao.searchLessCommonAll(TableName.SUMMARIZE_RECIEVER, recieverLess);
        int recieverCount = recieverSumList.size();

        //计算未交人员列表
        Map<String, String> recieverMap = new HashMap<String, String>();
        for (int i = 0; i < recieverCount; i++) {//应交总结人的Map集合
            recieverMap.put(DBObjectUtils.getString(recieverSumList.get(i), "uuid"), DBObjectUtils.getString(recieverSumList.get(i), "name"));
        }

        for (int j = 0; j < alreadyCount; j++) {//如果已交总结，则从应交总结人的Map中删除，剩下的为未交总结人
            String uuid = DBObjectUtils.getString(alreadySumList.get(j), "uuid");
            if (recieverMap.containsKey(uuid)) {
                recieverMap.remove(uuid);
            }
        }

        //应交人数
        result.put("recievers", recieverCount);
        //已交总结人数
        result.put("alreadys", recieverCount - recieverMap.size());
        //未交总结人数
        result.put("notAlreadys", recieverMap.size());
        //未交总结人姓名列表
        result.put("notAlreadyList", recieverMap.values());

        return result;
    }
}
